<template>
  <el-menu default-active="2" :collapse="collapsed" collapse-transition router :default-active="$route.path"
           unique-opened class="el-menu-vertical-demo" background-color="#334157" text-color="#fff"
           active-text-color="#ffd04b">

    <div class="logobox">
      <img class="logoimg" src="../assets/img/logo.png" alt="">
    </div>
    <el-submenu v-for="menu in allmenu" :key="menu.menuid" :index="menu.menuname">
      <template slot="title">
        <i class="iconfont" :class="menu.icon"></i>
        <span>{{ menu.menuname }}</span>
      </template>
      <el-menu-item-group>
        <el-menu-item v-for="chmenu in menu.menus" :index="'/'+chmenu.url" :key="chmenu.menuid">
          <i class="iconfont" :class="chmenu.icon"></i>
          <span>{{ chmenu.menuname }}</span>
        </el-menu-item>
      </el-menu-item-group>
    </el-submenu>
  </el-menu>
</template>
<script>


export default {
  name: 'leftnav',
  data() {
    return {
      collapsed: false,
      allmenu: []
    }
  },
  // 创建完毕状态(里面是操作)
  created() {
    // 获取图形验证码
    let res = {
      success: true,
      data: [
        {
          menuid: 1,
          icon: 'li-icon-xiangmuguanli',
          menuname: '首页',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 1,
              icon: 'icon-cat-skuQuery',
              menuname: '界面管理',
              hasThird: 'N',
              url: 'index/device_back/device_index',
              menus: null
            },
          ]
        },
        {
          menuid: 2,
          icon: 'li-icon-dingdanguanli',
          menuname: '人员管理',
          hasThird: null,
          url: null,
          menus: [
            {
              menuid: 1,
              icon: 'icon-fl-renyuan',
              menuname: '用户管理',
              hasThird: 'N',
              url: 'index/group/user',
              menus: null
            },
          ]
        },
        {
          menuid: 3,
          icon: 'li-icon-device',
          menuname: '设备管理',
          hasThird: null,
          url: null,
          menus: [
          //加你的设计模块，建在Views的device里边
            {
              menuid: 1,
              icon: 'icon-fl-deviceMessage',
              menuname: '设备信息管理',
              hasThird: 'N',
              url: 'index/device/device',
              menus: null
            },
            {
              menuid: 2,
              icon: 'icon-fl-shebeifenlei',
              menuname: '设备信息分类管理',
              hasThird: 'N',
              url: 'index/devicefl/devicefl',
              menus: null
            }
          ]
        },
        {
          menuid: 4,
          icon: 'li-icon-deviceLog',
          menuname: '设备日志管理',
          hasThird: null,
          url: null,
          menus: [
          //  建在Views的deviceLog里边
            {
              menuid: 1,
              icon: 'icon-fl-deviceLogMessage',
              menuname: '日志信息',
              hasThird: 'N',
              url: 'index/deviceLog/deviceLog',
              menus: null
            },
            {
              menuid: 2,
              icon: 'icon-fl-deviceLogType',
              menuname: '日志类型',
              hasThird: 'N',
              url: 'index/deviceLog/deviceLogType',
              menus: null
            },
            {
              menuid: 3,
              icon: 'icon-fl-sysLog',
              menuname: '系统日志',
              hasThird: 'N',
              url: 'index/deviceLog/sysLog',
              menus: null
            },
            {
              menuid: 4,
              icon: 'icon-fl-taskLog',
              menuname: '任务日志',
              hasThird: 'N',
              url: 'index/deviceLog/taskLog',
              menus: null
            },
            {
              menuid: 5,
              icon: 'icon-fl-errorLog',
              menuname: '错误日志',
              hasThird: 'N',
              url: 'index/deviceLog/errorLog',
              menus: null
            },
          ]
        },
        {
          menuid: 5,
          icon: 'li-icon-device_question',
          menuname: '故障管理',
          hasThird: null,
          url: null,
          menus: [
          //  加你设计的表模块 如：故障记录表的Vue模块建在
          //   Views的device_question里边
            {
              menuid: 1,
              icon: 'icon-fl-renyuan',
              menuname: '故障管理',
              hasThird: 'N',
              url: 'index/fault/fault',
              menus: null
            },
            {
              menuid: 2,
              icon: 'icon-fl-renyuan',
              menuname: '故障统计',
              hasThird: 'N',
              url: 'index/fault/fault_mag',
              menus: null
            },
          ]
        },
        {
          menuid: 6,
          icon: 'li-icon-device_service',
          menuname: '维修管理',
          hasThird: null,
          url: null,
          menus: [
          // 建在Views的device_service里边
            {
              menuid: 1,
              icon: 'icon-fl-renyuan',
              menuname: '维修管理',
              hasThird: 'N',
              url: 'index/repair/repair',
              menus: null
            },
            {
              menuid: 2,
              icon: 'icon-fl-renyuan',
              menuname: '维修部门管理',
              hasThird: 'N',
              url: 'index/repair/repair_depart',
              menus: null
            },
            {
              menuid: 3,
              icon: 'icon-fl-renyuan',
              menuname: '维修状态',
              hasThird: 'N',
              url: 'index/repair/repair_status',
              menus: null
            },
            {
              menuid: 4,
              icon: 'icon-fl-renyuan',
              menuname: '维修地址',
              hasThird: 'N',
              url: 'index/repair/repair_addr',
              menus: null
            },
            {
              menuid: 5,
              icon: 'icon-fl-renyuan',
              menuname: '维修紧急程度',
              hasThird: 'N',
              url: 'index/repair/repair_urgency',
              menus: null
            },
          ]
        },
        {
          menuid: 7,
          icon: 'li-icon-houqin',
          menuname: '后勤管理',
          hasThird: null,
          url: null,
          menus: [
          //建在Views的device_backService里边
            {
              menuid: 1,
              icon: 'icon-fl-dingdan',
              menuname: '后勤订单',
              hasThird: 'N',
              url: 'index/logistics/Order',
              menus: null
            },
            {
              menuid: 2,
              icon: 'icon-fl-lingjian',
              menuname: '后勤零件',
              hasThird: 'N',
              url: 'index/logistics/Part',
              menus: null
            },

          ]
        },
      ],
      msg: 'success'
    }
    this.allmenu = res.data

    // 通过请求去查询数据库中的菜单,动态生成菜单列表
    // menu(localStorage.getItem('logintoken'))
    //   .then(res => {
    //     console.log(JSON.stringify(res))
    //     if (res.success) {
    //       this.allmenu = res.data
    //     } else {
    //       this.$message.error(res.msg)
    //       return false
    //     }
    //   })
    //   .catch(err => {
    //     this.$message.error('菜单加载失败，请稍后再试！')
    //   })
    // 监听
    this.$root.Bus.$on('toggle', value => {
      this.collapsed = !value
    })
  }
}
</script>
<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 240px;
  min-height: 400px;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
  text-align: left;
}

.el-menu-item-group__title {
  padding: 0px;
}

.el-menu-bg {
  background-color: #1f2d3d !important;
}

.el-menu {
  border: none;
}

.logobox {
  height: 40px;
  line-height: 40px;
  color: #9d9d9d;
  font-size: 20px;
  text-align: center;
  padding: 20px 0px;
}

.logoimg {
  height: 40px;
}
</style>
